package com.jinsi.controller.ylt;

import com.jinsi.constant.YltConstant;
import com.jinsi.service.ylt.UserSealService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jinsi.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName UserSealController
 * @Content 用户封号Controller
 * @Author 姚龙腾
 * @Date 2022/10/12 11:53
 */
@RestController
@RequestMapping("/YltUser")
@Slf4j
public class UserSealController {

    @Autowired
    private UserSealService userSealService;

    /**
     * 获取用户封号列表信息
     * @param page
     * @param limit
     * @return R
     */
    @RequestMapping("/UserManage/getUserSeal")
    public R getUserSeal(Integer page, Integer limit){
        PageHelper.startPage(page,limit);
        List<Map<String, Object>> list = userSealService.getAll();
        PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }


    /**
     * 根据输入信息进行模糊查询
     * @param page
     * @param limit
     * @param userName
     * @param userAccount
     * @param sealTime
     * @return R
     */
    @RequestMapping("/UserManage/getUserSealByLike")
    public R getUserSealByLike(Integer page, Integer limit, String userName, String userAccount, String sealTime){
        PageHelper.startPage(page,limit);
        List<Map<String, Object>> list = userSealService.getAllByLike(userName, userAccount, sealTime);
        PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
        return R.custom(YltConstant.LAYUI_CODE,
                YltConstant.LAYUI_MSG,
                pageInfo.getList(),
                pageInfo.getTotal());
    }


    /**
     * 修改用户封号状态
     * @param sealId
     * @param sealState
     * @return R
     */
    @RequestMapping("/UserManage/upUserSeal")
    public R upUserSeal(Integer sealId,Integer sealState){
        try {
            userSealService.upUserSeal(sealId,sealState);
            log.info("修改用户封号状态 upUserSeal方法执行成功,修改封号id：${}",sealId);
            return R.ok();
        } catch (Exception e) {
            log.error("修改用户封号状态 upUserSeal方法执行失败,报错原因：${}",e);
            return R.error();
        }
    }


    /**
     * 根据用户id获取封停信息
     * @param userId
     * @return R
     */
    @RequestMapping("/UserManage/getUserSealId")
    public R getUserSealId(Integer userId){
        return R.ok(userSealService.getUserSealId(userId));
    }
}
